Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: updating mocks for tests to test mender-connect JWT request handling #2108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SebOpsahl
Copy link

@SebOpsahl SebOpsahl commented May 2, 2024

This PR is made to change the mocks and testflow in tests to better fit the new implementation of the PR 👉 mendersoftware/mender-connect#134. This PR fixes it so mender-connect requests a new JWT token on its own, so its not dependent on mender-update to do so. Previously FetchJWTToken() wasn’t called which wouldn’t let it call the JWT token independently, which made it dependent on mender-update. The proposed fix is using FetchJWTToken() to fetch the token, to then for WaitForJwtTokenStateChange() to retrieve it in it’s waiting. The old mocks and test flow for the tests seemed to be more tailored to test the functionality with GetJWTToken(). This PR proposes a change in the mocks and test flow to better test the new implementation.

Changelog: None

Ticket: MEN-6877

@mender-test-bot
Copy link

@SebOpsahl, Let me know if you want to start the integration pipeline by mentioning me and the command "start pipeline".


my commands and options

You can trigger a pipeline on multiple prs with:

  • mentioning me and start pipeline --pr mender/127 --pr mender-connect/255

You can start a fast pipeline, disabling full integration tests with:

  • mentioning me and start pipeline --fast

You can trigger GitHub->GitLab branch sync with:

  • mentioning me and sync

You can cherry pick to a given branch or branches with:

  • mentioning me and:
 cherry-pick to:
 * 1.0.x
 * 2.0.x

@SebOpsahl SebOpsahl force-pushed the master branch 2 times, most recently from b864e2d to b7a8fb9 Compare May 2, 2024 17:56
@SebOpsahl
Copy link
Author

Screenshot from 2024-05-02 20-05-08

The updated test functions were tested with the new implementation (solution proposed for MEN-6877 in another PR) which was successful.

@SebOpsahl SebOpsahl requested a review from lluiscampos May 2, 2024 18:05
Copy link
Contributor

@lluiscampos lluiscampos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work getting the mock to behave and the tests passing 💪

I think however that we have introduced many unjustified changes in the test flow, and I'd like to discuss or revert them (see comments below).

Your commit is pretty good. Some tips to make it better:

</interface>
</node>
"""
<node>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections on changing from tabs to spaces 👍 This was probably what got your editor confused.

Comment on lines 31 to 35
</method>
<signal name="JwtTokenStateChange">
<arg type="s" name="token"/>
<arg type="s" name="server_url"/>
</signal>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicpick: wrong indentation

Suggested change
</method>
<signal name="JwtTokenStateChange">
<arg type="s" name="token"/>
<arg type="s" name="server_url"/>
</signal>
</method>
<signal name="JwtTokenStateChange">
<arg type="s" name="token"/>
<arg type="s" name="server_url"/>
</signal>

@@ -193,14 +202,18 @@ def test_mender_connect_auth_changes(
"""Test that mender-connect can re-establish the connection on D-Bus signals"""

try:
dbus_set_token_and_url(connection, "token1", "http://localhost:5000")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this we should keep as it was. The test scenario here is that the server is up and running already when mender-connect starts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here? I still believe that we should simulate that the server is up and running before mender-connect starts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey, since the tests fail due to timeout when we first set the token and url, and then let mender-connect start. But is successful when we do it after mender-connect has started. I will investigate the issue 👍

tests/acceptance/test_mender-connect.py Show resolved Hide resolved
Comment on lines 210 to 222
dbus_set_token_and_url(connection, "token1", "http://localhost:5000")

# sleep for a while to ensure a connection happens
time.sleep(60)
dbus_emit_signal(connection)
signal_time = qemu_system_time(connection)

# wait for first connect
_ = wait_for_string_in_log(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sleep here looks suspicious to me. The wait_for_string_in_log function below will wait a given amount of time for the required message, so we shouldn't need to wait before.

You probably meant to wait for mender-connect to start-up before we can instruct the mock to emit the signal, so that will be short sleep between systemctl ... start mender-connect and dbus_emit_signal.

A much better approach that we draft some time ago on the whiteboard would be to have a flag in the mock that can save when mender-connect has called FetchJwtToken and then the test can wait for that to then emit the signal. This is a bit more complex but will be a better test (right now we are blindly assuming that mender-connect requested a token before we emit the signal).

Comment on lines 238 to 241
dbus_set_token_and_url(connection, "token2", "http://localhost:6000")
time.sleep(30)
signal_time = qemu_system_time(connection)
dbus_set_token_and_url_and_emit_signal(
connection, "token2", "http://localhost:6000"
)
dbus_emit_signal(connection)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should stay as it was, why we need to sleep between setting state in the mock and emitting the signal?

@@ -277,14 +290,18 @@ def test_mender_connect_reconnect(
"""Test that mender-connect can re-establish the connection on remote errors"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much of what I commented in the previous test case is applicable to this one, so I won't review it in detail just yet 👀

_ = wait_for_string_in_log(
connection, kill_time, 300, "error reconnecting:",
connection, kill_time, 300, "waiting for reconnect",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why won't in this case eventually come back to error reconnecting? What has changed in mender-connect for this case? 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on returns made in the the tests it returned waiting for reconnect given the test case, while the test was made to wait for error reconnecting which made it fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey

@SebOpsahl SebOpsahl force-pushed the master branch 3 times, most recently from 691c712 to 702954b Compare May 26, 2024 21:10
…connect

This PR is made to change the mocks and testflow in tests to better fit the new implementation of the PR 👉 mendersoftware/mender-connect#134. This PR fixes it so `mender-connect` requests a new JWT token on its own, so its not dependent on `mender-update` to do so. Previously `FetchJWTToken()` wasn’t called which wouldn’t let it call the JWT token independently, which made it dependent on `mender-update`. The proposed fix is using `FetchJWTToken()` to fetch the token, to then for `WaitForJwtTokenStateChange()` to retrieve it in it’s waiting. The old mocks and test flow for the tests seemed to be more tailored to test the functionality with `GetJWTToken()`. This PR proposes a change in the mocks and test flow to better test the new implementation.

Changelog: None

Ticket: MEN-6877
Signed-off-by: Sebastian Opsahl <[email protected]>
@SebOpsahl
Copy link
Author

With the new changes made to the actual implementation of the ticket found here 👉 mendersoftware/mender-connect#134 (comment) and the new test implementation where the test ensures an connection instead of just sleeping and assuming an connection everything should look good

@SebOpsahl
Copy link
Author

@mender-test-bot start pipeline --pr mender-connect/134

@mender-test-bot
Copy link

Hello 😺 I created a pipeline for you here: Pipeline-1306885344

Build Configuration Matrix

Key Value
BUILD_BEAGLEBONEBLACK true
BUILD_CLIENT true
BUILD_QEMUX86_64_BIOS_GRUB true
BUILD_QEMUX86_64_BIOS_GRUB_GPT true
BUILD_QEMUX86_64_UEFI_GRUB true
BUILD_VEXPRESS_QEMU true
BUILD_VEXPRESS_QEMU_FLASH true
BUILD_VEXPRESS_QEMU_UBOOT_UEFI_GRUB true
META_MENDER_REV pull/2108/head
RUN_BACKEND_INTEGRATION_TESTS true
RUN_INTEGRATION_TESTS true
TEST_QEMUX86_64_BIOS_GRUB true
TEST_QEMUX86_64_BIOS_GRUB_GPT true
TEST_QEMUX86_64_UEFI_GRUB true
TEST_VEXPRESS_QEMU true
TEST_VEXPRESS_QEMU_FLASH true
TEST_VEXPRESS_QEMU_UBOOT_UEFI_GRUB true

</node>
"""
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a big deal, though. But for the future:

Changing the indentation is unrelated to your changes. The commit would read much cleaner if we could have here only the method that we have added. If you want to modify the indentation it is best to do it on a separate commit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, the formatting test wouldn't pass unless i changed the formatting. I thought it may have been something with the formatter being updated. Is there any way I can come around the failing test without changing the formatting of the other parts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, the formatting test wouldn't pass unless i changed the formatting. I thought it may have been something with the formatter being updated. Is there any way I can come around the failing test without changing the formatting of the other parts?

I am not aware of any recent change. We use a fixed version of the formatting tool.

But in any case you could have formatted the existing code first, commit that, then add your changes.

Again, this is not a big deal so don't spend more time on it.

@@ -193,14 +202,18 @@ def test_mender_connect_auth_changes(
"""Test that mender-connect can re-establish the connection on D-Bus signals"""

try:
dbus_set_token_and_url(connection, "token1", "http://localhost:5000")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here? I still believe that we should simulate that the server is up and running before mender-connect starts.

connection, startup_time, 30, "Started Mender Connect service"
)

signal_time = qemu_system_time(connection)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use signal_time below (line 224) when looking for "Connection established..." in the log?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry my bad, fixed it now 👍

connection, startup_time, 30, "Started Mender Connect service"
)

signal_time = qemu_system_time(connection)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it now 👍

@@ -277,14 +294,22 @@ def test_mender_connect_reconnect(
"""Test that mender-connect can re-establish the connection on remote errors"""

try:
dbus_set_token_and_url(connection, "badtoken", "http://localhost:12345")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, the serer is expected to be running before mender-connect starts

_ = wait_for_string_in_log(
connection, kill_time, 300, "error reconnecting:",
connection, kill_time, 300, "waiting for reconnect",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey

# kill the server and wait for error
with_mock_servers[1].kill()
kill_time = qemu_system_time(connection)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is probably unnecessary and I vote for reverting it. It is in effect the same thing, but capturing the time before the action (in this case before killing the server) makes it consistent across the test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants